/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

*/

#ifndef SCENE_TEXTURE_H
#define SCENE_TEXTURE_H

#include <iostream>
#include "scenemanager/sceneelement.h"
#include "objects/vertex.h"
#include <QImage>
#include <QFile>
#include <QString>

using namespace std;

namespace scene {

class Texture : public SceneElement
{
  public:
    Texture(QString textFile):m_textFile(textFile)
    {
      m_img = new QImage();
      QString fileName = "assets/textures/" + textFile;
      
      if(!m_img->load(fileName)){
        cout << "NO SUCHE IMGAGE: " << fileName.toStdString();
          cin.get();
      }
      
    }
    ~Texture(){;}
    virtual void printElement()
    {
      cout << "TextureInfo: ";
      cout << m_name.toStdString() << "\n";
      cout << "file: " << m_textFile.toStdString() << "\n";
    }
    
    inline QString TextFile(){return m_textFile;}
    
    // TODO SPEED UP PIXEL() IS EXPENSIVE FUNCTION
    inline QRgb getColor(int x, int y){return m_img->pixel(x, y);}
    inline int width(){return m_img->width();}
    inline int height(){return m_img->height();}
    
    inline void setRepeat(int val){m_repeat = val;}
    inline int getRepeat(){return m_repeat;}
  private:
    QString m_textFile;
    QImage * m_img;
    int m_repeat;
};

}

#endif // SCENE_TEXTURE_H
